<?php

echo $this->Html->script('jquery.ui.core.min');
echo $this->Html->script('jquery.validate.min');
echo $this->Html->script('additional-methods');
echo $this->Html->script('jquery.ui.datepicker.min');
echo $this->Html->css('jquery-ui');
?>
<script type="text/javascript">
    $(document).ready(function(){
        $("form").validate({
            errorClass: "jqueryError",
            errorElement: 'label',
            debug: false,
            submitHandler: function(form) {
                $(':submit', form).attr('disabled', 'disabled').addClass('inactive');
                form.submit();
            }
        });
    });

    $(function(){
        var dates = $('#ProductCostvalidfrom, #ProductCostvalidto').datepicker({
            defaultDate: new Date(),
            changeMonth: true,
            changeYear: true,
            dateFormat: 'dd-mm-yy',
            onSelect: function(selectedDate) {
                var option = this.id == "ProductCostvalidfrom" ? "minDate" : "maxDate";
                var instance = $(this).data("datepicker");
                var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
                dates.not(this).datepicker("option", option, date);
            }
        });
    })
</script>
<?php

echo $this->Form->input('name', array(
    'label' => 'Name',
    'class' => 'required',
    'between' => $this->Html->tag('span', '(Only letters and numbers, atleast 2 characters)', array('class' => 'description'))
));

echo $this->Form->input('description', array(
    'label' => 'Description',
    'between' => $this->Html->tag('span', '(Product description)', array('class' => 'description'))
));

echo $this->Form->input('cost', array(
    'label' => 'Cost',
    'class' => 'required',
    'between' => $this->Html->tag('span', '(Only numbers, should be greater than 0)', array('class' => 'description'))
));

echo $this->Form->input('costvalidfrom', array(
    'label' => 'Cost Valid From',
    'class' => 'required',
    'type' => 'text',
    'between' => $this->Html->tag('span', '(Click the text field below and select a date from the calendar)', array('class' => 'description'))
));

echo $this->Form->input('costvalidto', array(
    'label' => 'Cost Valid To',
    'class' => 'required',
    'type' => 'text',
    'between' => $this->Html->tag('span', '(Click the text field below and select a date from the calendar)', array('class' => 'description'))
));

echo $this->Form->input('category_id', array(
    'label' => 'Category',
    'type' => 'select',
    'options' => $categories,
    'empty' => 'Select',
    'class' => 'required',
    'between' => $this->Html->tag('span', '(Select a category to which this product belongs)', array('class' => 'description'))
));

echo $this->Form->input('status', array(
    'label' => 'Status',
    'checked' => true,
    'after' => $this->Html->tag('span', '(Uncheck to set the status as "disabled")', array('class' => 'description'))
));
?>